package com.imooc.miaosha.Access;

import com.imooc.miaosha.domain.MiaoshaUser;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * @author liyuhui
 * 2018.1.19
 */
public class UserContext {
    private static Logger log = LoggerFactory.getLogger(UserContext.class);

    private static ThreadLocal<MiaoshaUser> userHolder = new ThreadLocal<MiaoshaUser>();

    public static void setUser(MiaoshaUser miaoshaUser) {
        log.info("userHolder存值："+ miaoshaUser.getId());
        userHolder.set(miaoshaUser);
    }

    public static MiaoshaUser getUser() {
        log.info("userHolder取值:" + userHolder.get().getId());
        return userHolder.get();
    }
}
